package personal.wang.worker;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @className: HeartbeatThread
 * @Description:
 * @Author: wangyifei
 * @Date: 2025/2/14 15:42
 */
public class HeartbeatThread{
    private static Logger logger = LoggerFactory.getLogger(HeartbeatThread.class);
    private Runnable heartbeatTask ;
    private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(4);
    public HeartbeatThread(Runnable heartbeatTask , int interval){
        this.heartbeatTask = heartbeatTask;
        scheduledExecutorService.scheduleAtFixedRate(heartbeatTask , 0 , interval , TimeUnit.SECONDS);
    }

    public static void main(String[] args) {
        Runnable task = ()->{
            logger.info("11111");
        };
        HeartbeatThread heartbeatThread = new HeartbeatThread(task , 1);
    }
}
